﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DAL;
using Entities;
using WebUI.Areas.Bots.Models;
using Services;

namespace WebUI.Areas.Bots.Controllers
{
    public partial class IndexController : BaseController
    {
        #region Member Variables

        readonly IUnitOfWork _uow;
        readonly IBotService _botService;

        #endregion

        #region Constructor

        public IndexController(IUnitOfWork uow, ISessionHelper sessionHelper, IBotService botService)
            : base(sessionHelper)
        {
            this._uow = uow;
            this._botService = botService;
        }

        #endregion

        #region Action Methods

        public virtual ViewResult Index()
        {
            //TODO:Remove General class
            IEnumerable<General> bots = _uow.BOTRepository.GetAll().Select(b => new General { Id = b.BotId, Name = b.BotName });
            return View(bots);
        }


        public virtual ActionResult Create()
        {
            _sessionHelper.Bot = new BOT();
            _sessionHelper.MaxStepReached = 0;
            return RedirectToAction(MVC.Bots.General.Index());
        }

        public virtual ViewResult Details(int id)
        {
            BOT bot = _botService.DisplayBot(id);
            return View(bot);
        }

        public virtual ActionResult Edit(int id)
        {
            _sessionHelper.Bot = _botService.EditBot(id);
            return RedirectToAction(MVC.Bots.General.Index());
        }

        [HttpPost]
        public virtual ActionResult Delete(int id)
        {
            _botService.Delete(id);
            //TODO:unit test the delete
            //TODO:unit test the edit
            //TODO:unit test the delete
            //TODO:unit test the add
            return RedirectToAction(MVC.Bots.Index.Index());
        }

        #endregion
    }
}